#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

struct cmp{
	bool operator()(const vector<int>& a, const vector<int>& b){
		if(a[1] != b[1]){
			return a[1] < b[1];
		}else{
			return a[0] < b[0];
		}
	}
}c;

int main(){
	
	vector< vector<int> > t;
	vector<int> a;

		a.push_back(1);
		a.push_back(2);
		a.push_back(1);
	t.push_back(a);
	a.clear();
		a.push_back(4);
		a.push_back(2);
		a.push_back(2);
	t.push_back(a);
	a.clear();
		a.push_back(3);
		a.push_back(1);
		a.push_back(3);
	t.push_back(a);
	a.clear();
	
	sort(t.begin(), t.end(), c);	

	
	vector< vector<int> >::iterator it;
	for(it = t.begin(); it != t.end(); ++it){
		a = *it;
		cout<< a[0] <<" "<< a[1] <<" "<< a[2] <<" "<<endl;
	}
	
	return 0;
}
